Public MustInherit Class CStateBase
    Protected m_NextState As New ArrayList()

    Public Function AddNextSate(ByVal state As CStateBase) As Boolean
        m_NextState.Add(state)
    End Function

    Protected Function GetNextState(ByVal task As CTaskBase) As CStateBase
        Dim i As Integer
        Dim result As CStateBase = Nothing
        For i = 0 To m_NextState.Count - 1
            Dim state As CStateBase = m_NextState.Item(i)
            If state.IsEnter(task) Then
                result = state
                Exit For
            End If
        Next i
        Return result
    End Function


    Protected Function GetNextState(ByVal task As CTaskBase, ByVal TargetClass As Type) As CStateBase
        Dim i As Integer

        Dim result As CStateBase = Nothing
        For i = 0 To m_NextState.Count - 1
            Dim state As CStateBase = m_NextState.Item(i)
            'Console.WriteLine("TARGET:{0},{1}", state.GetType, TargetClass)
            If state.GetType Is TargetClass Then
                If state.IsEnter(task) Then
                    result = state
                    Exit For
                End If
            End If
        Next i
        Return result
    End Function


    'Protected Function PopPrevState(ByVal task As CTaskBase) As CStateBase
    '    Return task.PopPrevState()
    'End Function


    Function DoBaseExecute(ByVal task As CTaskBase) As CStateBase
        Dim result As CStateBase
        result = DoExecute(task)
        'task.PushPrevState(Me)
        Return result
    End Function

    Function IsBaseEnter(ByVal task As CTaskBase) As Boolean
        Dim result As Boolean
        result = IsEnter(task)
        Return result
    End Function

    Function DoBaseExit(ByVal task As CTaskBase)
        Dim result As Boolean
        result = DoExit(task)
        Return result
    End Function




    Public MustOverride Function IsEnter(ByVal task As CTaskBase) As Boolean
    Public MustOverride Function DoExecute(ByVal task As CTaskBase) As CStateBase
    Public MustOverride Function DoExit(ByVal task As CTaskBase) As Boolean
End Class
